#!/bin/sh
#called from modemprobe
#delete current modem setting.
#v416 manage linuxant modems
#v432 Undo automatic HCF/HSF overrides if modem selection is already cleared, to require second erase to reset the overrides.
#101203 bk: modified.
#120201 BK: internationalized.
#120924 rerwin: Extend to all linuxant modems the modemx file removal on erase-with-no-modem-set,.

export TEXTDOMAIN=modemprobe_erase
export OUTPUT_CHARSET=UTF-8

KERNVER="`uname -r`"

rm -f /dev/modem

#v432 If no modem currently "detected", reset ALSA override of HSF driver (and vice versa).
if [ ! -e /etc/wvdial.conf ] \
  || grep -q -E '^Modem = (/dev/MYDEVM|MYDEVM)' /etc/wvdial.conf;then
 rm -f /etc/modprobe.d/modemx_dgc* #120924
 rm -f /etc/modprobe.d/modemx_hcf* #120924
 rm -f /etc/modprobe.d/modemx_hsf* #120924
fi #v432 end

#100908 Delete modem configuration files, to allow fresh start.
rm -f /etc/modprobe.d/modem_* #120924

#100909 Reset config file modem and alternate.
[ -e /etc/wvdial.conf ] \
 && sed -i \
  -e 's%^Modem = .*%Modem = MYDEVM%' \
  -e '/^#Modem = .*/d' \
  /etc/wvdial.conf #424

#v432 Remove ttyS_, ttySHCF, ttyHSF, & ttySL0 device links and nodes, to prevent wvdialconf from finding an incorrect device name after a modem-hardware change.
rm -f /dev/ttyS_* /dev/ttySHCF* /dev/ttySHSF* /dev/ttySL0 /dev/ttySM0

sed -i \
 -e /^agrsm$/d \
 -e /^dgcmodem$/d \
 -e /^ess$/d \
 -e /^hcfpcimodem$/d \
 -e /^hsfmodem$/d \
 -e /^intel53[67]ep$/d \
 -e /^ltmodem$/d \
 -e /^martian$/d \
 -e /^mwavem-1.0.2$/d \
 -e /^pctel$/d \
 -e /^slmodem$/d \
 -e /^Slmodemusb$/d \
 /etc/modules/firmware.dep.inst.${KERNVER} 2>/dev/null #101203 bugfix.

#v433 Remove initialization scripts for USB modems in case modem removed...
rm -f /etc/init.d/Dgcmodem
rm -f /etc/init.d/Slmodemusb

#101203 more
rm -f /etc/init.d/agrsm
rm -f /var/local/pupdial/hotpluggable

#101231 Since SmartLink USB modem no longer being used, kill its application daemon to avoid hanging system if modem unplugged after erase.
ALLPS="`busybox ps`"
[ "`echo "$ALLPS" | grep -w 'slmodemd' | grep -w '/dev/slusb0'`" != "" ] \
 && killall -q slmodemd

#xmessage "/dev/modem deleted, 'Modem' entry in /etc/wvdialconf initialized."
/usr/lib/gtkdialog/box_splash -placement center -close box -text "$(gettext "/dev/modem deleted, 'Modem' entry in /etc/wvdial.conf initialized. You need to reboot before trying PupDial again. Well, you do need to reboot for internal modems, as they get detected at bootup. For an external 'hotpluggable' nodem, there is no need to reboot -- if the modem is plugged in, run PupDial now (wait several seconds after plugging it in before starting PupDial)")" &

#101203 kill pupdial...
ALLPS="`busybox ps`"
PIDS="`echo "$ALLPS" | grep -E 'gtkdialog3 --center --program=MAINDIALOG|modemprobe|pupdial' | grep -v 'modemprobe_erase' | cut -f 1 -d ' ' | tr '\n' ' '`"
kill $PIDS 2>/dev/null
kill $PIDS 2>/dev/null

###END###
